﻿using Domain;
using IDal;
using Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Dal
{
    public class Service : IService
    {
         private readonly DbContext dbContext;

        private readonly DapperHelper dapperHelper;

        public Service(DbContext dbContext, DapperHelper dapperHelper)
        {
            this.dbContext = dbContext;
            this.dapperHelper = dapperHelper;
        }

        public async Task<int> Add()
        {
            var db = new DbContext().Db;
            var user = new T_User {Name="123",Password="12345678" };
            return await db.Insertable(user).ExecuteCommandAsync();
           
        }


        public async Task<int> AddMap()
        {
            var db = new DbContext().Db;
            var user = new Mapp { Name = "123" };
            return await db.Insertable(user).ExecuteCommandAsync();

        }

     

        public async Task<int> AddRole()
        {
           
            var user=new RoleMOdel { RoleName="123" };
            return await dbContext.Db.Insertable(user).ExecuteCommandAsync();
        }


        public async Task<int> AddUPdate()
        {
          

            var db = new DbContext().Db;
            var user = new T_User { Id=1, Name = "000", Password = "000" };
            return await db.Updateable(user).ExecuteCommandAsync();
        }

        public async Task<int> UserDel(int iD)
        {

            var db = new DbContext().Db;
            var user = new T_User { Id=6};
            return await db.Deleteable(user).ExecuteCommandAsync();
        }

        public async  Task<IEnumerable<T_User>> t_User(int id)
        {
            var sql = "SELECT * FROM users Where Id=@Id";
            return await dapperHelper.QueryAsync<T_User>(sql,new {id});
        }
    }
}
